链表的遍历

链表的遍历

# 单链表的实现
class SingleLinkList(object):
    def __init__(self, node=None):
        # head: 首结点
        self.head = node
    # 判断链表是否为空
    ......
    # 获取链表长度
    ......
    # 遍历链表
    def travel(self):
        # 游标记录当前所在的位置
        cur = self.head

        while cur is not None:
            print(cur.item)
            cur = cur.next